define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/userinvite/index',
                    add_url: 'user/userinvite/add',
                    edit_url: 'user/userinvite/edit',
                    del_url: 'user/userinvite/del',
                    multi_url: 'user/userinvite/multi',
                    table: 'user_invite_log',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'user_id', title: __('User_id')},
                        {field: 'nickname', title: '用户昵称'},
                        {field: 'realname', title: '用户姓名',visible:false},
                        {field: 'invite_1', title: __('Invite_1')},
                        {field: 'n1', title: '上一级推荐人昵称'},
                        {field: 'r1', title: '一级推荐人姓名',visible:false},
                        {field: 'invite_2', title: __('Invite_2')},
                        {field: 'n2', title: '上二级推荐人昵称'},
                        {field: 'r2', title: '二级推荐人姓名',visible:false},
                        {field: 'invite_3', title: __('Invite_3')},
                        {field: 'n3', title: '上三级推荐人昵称'},
                        {field: 'r3', title: '三级推荐人姓名',visible:false},
                        {field: 'invite_4', title: __('Invite_4')},
                        {field: 'n4', title: '四级推荐人昵称'},
                        {field: 'r4', title: '四级推荐人姓名',visible:false},
                        {field: 'time', title: __('Time'), operate:'RANGE', addclass:'datetimerange', formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});